const express = require('express')
const Result = require('../../models/Result')
const { decoded } = require('../../utils/index')
const { PRIVATE_KEY, JWT_EXPIRED } = require('../../utils/constant')
const {
  getFacilityList,
  editFacility,
  createFacility,
  deleteFacility
} = require('../../services/facility')
const jwt = require('jsonwebtoken')
const jwtAuth = require('../jwt')
// 注册路由
const router = express.Router()
router.use(jwtAuth)


//获取设施列表接口
router.get('/list', function(req, res, next) {
  getFacilityList(req.query).then(data => {
    new Result(data, '设施信息查询成功').success(res)
  }).catch(err => {
    new Result('设施信息查询失败').fail(res)
  })
})

//编辑设施接口
router.post('/edit', function(req, res, next) {
  editFacility(req.body).then(data => {
    new Result('操作成功').success(res)
  }).catch(err => {
    new Result('操作失败').fail(res)
  })
})

//创建设施接口
router.post('/create', function(req, res, next) {
  createFacility(req.body).then(data => {
    new Result('操作成功').success(res)
  }).catch(err => {
    new Result('操作失败').fail(res)
  })
})

//删除设施接口
router.post('/delete', function(req, res, next) {
  deleteFacility(req.body).then(data => {
    new Result('操作成功').success(res)
  }).catch(err => {
    new Result('操作失败').fail(res)
  })
})


module.exports = router